//class Figure
Figure = function(canvasName, x, y, width, height)
{
    Node.call(this, canvasName, x, y, width, height, true);

    this.MOVE_SPEED   = 0.01;
    this.ROTATE_SPEED = 0.3;
    this.m_velocityX = 0;
    this.m_velocityY = 0;
}

InheritanceManager.extend(Figure, Node);

Figure.prototype.init = function()
{
    Figure.superclass.init.call(this);
}

Figure.prototype.update = function(dt)
{   
    this.moveBy(this.m_velocityX * dt * this.MOVE_SPEED, this.m_velocityY * dt * this.MOVE_SPEED);
    this.m_angle += dt * this.ROTATE_SPEED;
    Figure.superclass.update.call(this);
}

Figure.prototype.setVelocity = function(x, y)
{
    this.m_velocityX = x;
    this.m_velocityY = y;
}

Figure.prototype.collide = function(node)
{
    Figure.superclass.collide.call(this, node);

    var wy = (this.m_width  + node.m_width)  * (this.m_y - node.m_y);
    var hx = (this.m_height + node.m_height) * (this.m_x - node.m_x);

    if (wy > hx)
    {
        if (wy > -hx)
        {
            // bottom
            this.m_velocityY = -this.m_velocityY;
        }
        else
        {
            // left
            this.m_velocityX = -this.m_velocityX;
        }
    }
    else
    {
        if (wy > -hx)
        {
            // right
            this.m_velocityX = -this.m_velocityX;
        }
        else
        {
            // top
            this.m_velocityY = -this.m_velocityY;
        }
    }
}

// class Wall
Wall = function(canvasName, x, y, width, height)
{
    Figure.call(this, canvasName, x, y, width, height, false);
}

InheritanceManager.extend(Wall, Node);

Wall.prototype.doDraw = function(node)
{
    node.m_context.beginPath();
    node.m_context.rect(-(node.m_width / 2), -(node.m_height / 2), node.m_width, node.m_height);
    node.m_context.closePath();
    node.m_context.fillStyle = 'brown';
    node.m_context.fill();
}